package uk.co.aetherworks.active_devices;

/*
 * Ped-ome
 *
 * ActiveDevices - Maintains a list of the Monome and Arc Devices
 * detected by SerialOSC
 *
 * Joe Handford aka Knecht 2011
 *
 */ 

// Misc Include Files
import java.util.*;
import java.io.*;

// aetherworks imports
import uk.co.aetherworks.debug.*;

public class ActiveDevices extends Debuggable {

	Map<String, Integer> devices; // Map of: device name, port
	Vector<String> deviceNames;   // List of: device names
	
	public ActiveDevices() {
		devices = new HashMap<String, Integer>();
		deviceNames = new Vector<String>();
	}
	
	public void addDevice(String deviceName, int port) {
		DEBUG("deviceName: " + deviceName);
		DEBUG("port: " + port + "\n");
		devices.put(deviceName, new Integer(port));
		deviceNames.addElement(deviceName);
	}

	public void printDevices() {
		DEBUG("active devices:");
		Iterator devNameIt = deviceNames.iterator();
		String currName;
		while (devNameIt.hasNext()) {
			currName = devNameIt.next().toString();
			DEBUG("device:" + currName + "; port: " + devices.get(currName).intValue());
		}
		DEBUG("");
	}
	
	public String[] getDevices() {
	   String[] deviceArray = new String[deviceNames.size()];
	   deviceNames.toArray(deviceArray);
	   return deviceArray;
	}
	
	public int getPortForDevice(String deviceName) {
		return devices.get(deviceName);
	}
}
